﻿<? function Ping($host, $timeout = 10)
{
    $output = array();
    $com = 'ping -n -w ' . $timeout . ' -c 10 ' . escapeshellarg($host);
    
    $exitcode = 0;
    exec($com, $output, $exitcode);

    if ($exitcode == 0 || $exitcode == 1)
    { 
        foreach($output as $cline)
        {
            if (strpos($cline, ' bytes from ') !== FALSE)
            {
                $out = (int)ceil(floatval(substr($cline, strpos($cline, 'time=') + 5)));
                return $out;
            }
        }
    }
    return FALSE;
} 


$ping = Ping('ya.ru');

echo $ping."<hr>";

if ($ping === FALSE)
    echo 'Не пингецца';
else if ($ping > 30)
    echo 'Пинг Больше 30';
else
    echo 'Всьо Ок))!';  

?>
